package com.ziyucoding.springboot.labs.lab3.rocketmqdemo.consumer;

import com.ziyucoding.springboot.labs.lab3.rocketmqdemo.message.Demo4Message;
import com.ziyucoding.springboot.labs.lab3.rocketmqdemo.message.Demo5Message;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 示例5的消费者（用于广播消费）
 *
 * @author ziyucoding
 * @date 2022-10-24
 **/
@Component
@RocketMQMessageListener(
        topic = Demo5Message.TOPIC,
        consumerGroup = "demo5-consumer-group-" + Demo5Message.TOPIC,
        messageModel = MessageModel.BROADCASTING // 设置为广播消费
)
public class Demo5Consumer implements RocketMQListener<Demo5Message> {

    private Logger logger = LoggerFactory.getLogger(Demo5Consumer.class);

    @Override
    public void onMessage(Demo5Message message) {
        logger.info("[onMessage][线程编号：{} 消息内容：{}]", Thread.currentThread().getId(), message);
    }
}
